package com.example.suspensionbardemo

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ImageView
import com.gyf.immersionbar.ImmersionBar

import com.google.android.material.appbar.CollapsingToolbarLayout

import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.appbar.AppBarLayout.OnOffsetChangedListener
import com.google.android.material.floatingactionbutton.FloatingActionButton


class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //setContentView(R.layout.activity_main1)

        setContentView(R.layout.activity_main2)
        ImmersionBar.with(this)
            .statusBarView(R.id.view)
            //.statusBarDarkFont(true)   //状态栏字体是深色，不写默认为亮色
            .navigationBarColor(android.R.color.white)
            .autoDarkModeEnable(true, 0.2f)
            .init();
        val appBarLayout = findViewById<AppBarLayout>(R.id.app_bar)
        val collapsingToolbarLayout = findViewById<CollapsingToolbarLayout>(R.id.toolbar_layout)
        collapsingToolbarLayout.post {
            val offHeight = collapsingToolbarLayout.height - ImmersionBar.getStatusBarHeight(this)
            appBarLayout.addOnOffsetChangedListener(OnOffsetChangedListener { appBarLayout1: AppBarLayout?, i: Int ->
                ImmersionBar
                    .with(this)
                    .statusBarDarkFont(Math.abs(i) >= offHeight, 0.2f)
                    .init()
            })
        }



        findViewById<ImageView>(R.id.img).setOnClickListener {
            startActivity(Intent(this, SecondActivity::class.java))
        }

        findViewById<FloatingActionButton>(R.id.fab).setOnClickListener {
            startActivity(Intent(this, RefreshViewPager2Activity::class.java))
        }
        findViewById<FloatingActionButton>(R.id.fab2).setOnClickListener {
            startActivity(Intent(this, RefreshViewPager1Activity::class.java))
        }

    }
}